package com.ruoyi.yf.test.http;

import com.ruoyi.yf.test.spider.Passage;

import java.io.File;
import java.util.concurrent.BlockingQueue;

/**
*
*作者:yellowcong
*日期:2017/11/24
*時間:10:09:13
*描述:
*/
public class PageThread implements Runnable{
    private BlockingQueue<String> queue ;

    public PageThread(BlockingQueue<String> queue) {
        super();
        this.queue = queue;
    }

    public void run() {
        try {
            while(this.queue.size()>0) {
                String url = this.queue.take();
                Passage passage = WebUtils.getPageData(url);
//              System.out.println("\r\n当前线程\t"+Thread.currentThread().getName()+"还剩下"+this.queue.size()+"个");
                FileUtils.copyStr2File(passage.getContent(), new File(Constants.OUT_PATH+File.separator+passage.getTitle()+".txt"));
                System.out.printf("当前线程%s,文章名称%s,还剩下%s个\r\n", Thread.currentThread().getName(),passage.getTitle(),this.queue.size());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}